import 'package:flutter/material.dart';

class WyAnimatedOpacity extends StatefulWidget {
  @override
  _WyAnimatedOpacityState createState() => _WyAnimatedOpacityState();
}

class _WyAnimatedOpacityState extends State<WyAnimatedOpacity> {
  int index = 0;
  bool click = false;

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(
        title: Text('Opacity与AnimatedOpacity'),
      ),
      body:_createAnamation(),
    );
  }

  _createRow() {
    return Row(
      mainAxisAlignment: MainAxisAlignment.center,
      children: <Widget>[
        Container(
          height: 80,
          width: 80,
          color: Colors.red,
          alignment: Alignment.center,
          child: Text(
            '1',
            style: TextStyle(color: Colors.white),
          ),
        ),
        Opacity(
          opacity: 0.0,
          child: Container(
            height: 80,
            width: 80,
            color: Colors.green,
            alignment: Alignment.center,
            child: Text(
              '2',
              style: TextStyle(color: Colors.white),
            ),
          ),
        ),
        Container(
          height: 80,
          width: 80,
          color: Colors.blue,
          alignment: Alignment.center,
          child: Text(
            '3',
            style: TextStyle(color: Colors.white),
          ),
        ),
      ],
    );
  }

  _createMengceng() {
    return Stack(
      children: <Widget>[
        Image.network(
          'https://gimg2.baidu.com/image_search/src=http%3A%2F%2Fimg.jj20.com%2Fup%2Fallimg%2F4k%2Fs%2F02%2F2109242332225H9-0-lp.jpg&refer=http%3A%2F%2Fimg.jj20.com&app=2002&size=f9999,10000&q=a80&n=0&g=0n&fmt=jpeg?sec=1642946916&t=4b8284d53f2fc6fdd0524beb337a57c8',
        ),
        Positioned.fill(
          child: Opacity(
            opacity: 0.5,
            child: Container(
              decoration: const BoxDecoration(
                gradient: LinearGradient(
                    colors: [Colors.white, Colors.blue],
                    begin: Alignment.bottomCenter,
                    end: Alignment.topCenter),
              ),
            ),
          ),
        ),
      ],
    );
  }

  _createAnamation() {
    return Stack(
      children: <Widget>[
        Image.network(
          'https://gimg2.baidu.com/image_search/src=http%3A%2F%2Fimg.jj20.com%2Fup%2Fallimg%2F4k%2Fs%2F02%2F2109242332225H9-0-lp.jpg&refer=http%3A%2F%2Fimg.jj20.com&app=2002&size=f9999,10000&q=a80&n=0&g=0n&fmt=jpeg?sec=1642946916&t=4b8284d53f2fc6fdd0524beb337a57c8',
        ),
        Positioned.fill(
          child: AnimatedOpacity(
            onEnd: () {
              print("onEnd");
              setState(() {
                click = !click;
              });
            },
            duration: const Duration(seconds: 3),
            opacity: click ? 0.2 : 0.8,
            child: Container(
              decoration: BoxDecoration(
                gradient: LinearGradient(
                  colors: [Colors.white, Colors.grey],
                ),
              ),
            ),
          ),
        ),
      ],
    );
  }
}
